import allure

from automation_api.base.litemail import LiteMail


class Coupon(LiteMail):
    @allure.step('添加优惠卷')
    def add_coupon(self, data):
        """
        添加优惠券
        :param data:
        :return:
        """
        url = self.base_url + "/coupon/create"
        req_data = {
            "method": "post",
            "url": url,
            # 如何获取cookies？
            "cookies": {
                "JSESSIONID": self.token,
                "X-Litemall-Admin-Token": self.token
            },
            "json": data
        }
        return self.send_request(req_data).json()

    @allure.step('查询优惠卷')
    def select_coupon(self, data):
        """
        查询优惠券
        :param data:
        :return:
        """
        url = self.base_url + "/coupon/list"
        req_data = {
            "method": "GET",
            "url": url,
            # 如何获取cookies？
            "cookies": {
                "JSESSIONID": self.token,
                "X-Litemall-Admin-Token": self.token
            },
            "params": data
        }
        return self.send_request(req_data).json()

    @allure.step('删除优惠卷')
    def delete_coupon(self, data):
        """
        删除优惠券
        :param data:
        :return:
        """
        url = self.base_url + "/coupon/delete"
        req_data = {
            "method": "post",
            "url": url,
            # 如何获取cookies？
            "cookies": {
                "JSESSIONID": self.token,
                "X-Litemall-Admin-Token": self.token
            },
            "json": data
        }
        return self.send_request(req_data).json()
